package com.woniu.park.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

public class ErrUtil {

    public static String extract(BindingResult bindingResult){
        List<FieldError> fieldErrors = bindingResult.getFieldErrors();
        StringBuilder sb = new StringBuilder();
        if (!fieldErrors.isEmpty()) {
            for (FieldError e : fieldErrors) {
                sb.append(e.getField()).append(":").append(e.getDefaultMessage())
                        .append(",");
            }
            sb.deleteCharAt(sb.length()-1);

        }
        return sb.toString();
    }
}
